package com.jerry.config;

import com.jerry.interceptor.UserSecurityInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * Filename:    InterceprotsConfig
 * Description:
 * Copyright:   Copyright (c)2016
 * Company:     lngtop
 *
 * @author: 谢余锋
 * @version: 1.0
 * Create at:   2016/9/8 13:57
 * <p/>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2016/9/8      谢余锋        1.0        1.0 Version
 */
@Configuration
public class InterceptorsConfig extends WebMvcConfigurerAdapter {

    @Bean
    UserSecurityInterceptor authenticationInterceptor() {
        return new UserSecurityInterceptor();
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new CurrentUserResolver());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor());
        super.addInterceptors(registry);
    }

}
